//
//  WeiboNode.m
//  yuikemall
//
//  Created by yuike5 yuike5 on 12-2-6.
//  Copyright (c) 2012年 yuike. All rights reserved.
//

#import "Status.h"
#import "WeiboNode.h"

@implementation WeiboNode
@synthesize created_at;
@synthesize text;
@synthesize source;
@synthesize idx;
@synthesize user;
@synthesize sina_deleted;
@synthesize sina_retweeted;
//self. head = [dict valueForKey:@"head"]; // http://app.qlogo.cn/mbloghead/39cd8c536eb46a9bcea6/50



-(id)initWithSinaWeibo:(NSDictionary*)dict
{
    self = [super init];
    if (self) {
        // Initialization code here.
        self. created_at = [dict valueForKey:@"created_at"];
        self. text = [dict valueForKey:@"text"];
        self. source = [dict valueForKey:@"source"];
        self. idx = [[dict valueForKey:@"id"] longLongValue];
        NSDictionary* temp = (NSDictionary*)[dict valueForKey:@"user"];
        self.user = [[[WeiboUserNode alloc] initWithSinaUser:temp] autorelease];
        
//        Status* status = [Status  statusWithJsonDictionary:dict];
//        self.created_at = status.timestamp;
        long long createdAt = [dict getTimeValueForKey:@"created_at" defaultValue:0];
        self.created_at = [NSString stringWithFormat:@"%lld", createdAt];
        
        id obj = [dict valueForKey:@"deleted"];
        self.sina_deleted = (!obj ? false : [obj boolValue]);
        
        // 转发微博        
        NSDictionary* retweetedStatusDic = [dict objectForKey:@"retweeted_status"];
		if (retweetedStatusDic) {
			sina_retweeted = YES;
		}
    }
    return self;
}

-(id)initWithTencWeibo:(NSDictionary*)dict
{
    self = [super init];
    if (self) {
        // Initialization code here.
        self. created_at = [NSString stringWithFormat:@"%lld", [[dict valueForKey:@"timestamp"] longLongValue]];
        self. text = [dict valueForKey:@"text"];
        self. source = [dict valueForKey:@"from"];
        self. idx = [[dict valueForKey:@"id"] longLongValue];
        self.user = [[[WeiboUserNode alloc] initWithTencWeibo:dict] autorelease];
        self.sina_deleted = false;
    }
    return self;
}


-(NSDate*) nsdate {
        return [NSDate dateWithTimeIntervalSince1970:[self.created_at   doubleValue]];
}


-(void)dealloc
{
    [ created_at release];
    [ text release];
    [ source release];
    [ user release];
    
    [super dealloc];
}
@end
